package com.cskaoyan.service.admin.impl;

import com.cskaoyan.bean.po.AdminConfigExpressPO;
import com.cskaoyan.bean.po.AdminConfigMallPO;
import com.cskaoyan.bean.po.AdminConfigOrderPO;
import com.cskaoyan.bean.po.AdminConfigWxPO;
import com.cskaoyan.mapper.AdminConfigMapper;
import com.cskaoyan.mapper.MarketSystemMapper;
import com.cskaoyan.service.admin.AdminConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 配置管理
 *
 * @author : Caspar
 * @since : 2022.06.26 18:40
 */
@Service
public class AdminConfigServiceImpl implements AdminConfigService {

    @Autowired
    AdminConfigMapper adminConfigMapper;

    @Autowired
    MarketSystemMapper marketSystemMapper;


    /**
     * 从market_system表中查询商场的配置信息，商场的每一条信息（位置、经度、纬度、qq等）在表中就是一列，
     * 如下:
     * id   key_name            key_value   add_time              update_time          deleted
     * 16	market_mall_address	武汉     	2019-12-08 19:11:18	   2019-12-08 19:11:18	0
     *
     * @return com.cskaoyan.bean.po.AdminConfigMallPO
     * @author: Caspar CXC
     * @since 2022/06/26 19:01
     */
    @Override
    public AdminConfigMallPO queryMallConfig() {

        AdminConfigMallPO adminConfigMallPO = new AdminConfigMallPO();

        String marketMallAddress = adminConfigMapper.queryMarketMallAddress();
        adminConfigMallPO.setMarket_mall_address(marketMallAddress);
        String marketMallLatitude = adminConfigMapper.queryMarketMallLatitude();
        adminConfigMallPO.setMarket_mall_latitude(marketMallLatitude);
        String marketMallLongitude = adminConfigMapper.queryMarketMallLongitude();
        adminConfigMallPO.setMarket_mall_longitude(marketMallLongitude);
        String marketMallName = adminConfigMapper.queryMarketMallName();
        adminConfigMallPO.setMarket_mall_name(marketMallName);
        String marketMallPhone = adminConfigMapper.queryMarketMallPhone();
        adminConfigMallPO.setMarket_mall_phone(marketMallPhone);
        String marketMallQQ = adminConfigMapper.queryMarketMallQQ();
        adminConfigMallPO.setMarket_mall_qq(marketMallQQ);

        return adminConfigMallPO;
    }

    /**
     * 更新商城中的配置信息
     *
     * @param adminConfigMallPO
     * @return void
     * @author: Caspar CXC
     * @since 2022/06/26 19:30
     */
    @Override
    public void updateMarketMallConfig(AdminConfigMallPO adminConfigMallPO) {

        String address = adminConfigMallPO.getMarket_mall_address();
        adminConfigMapper.updateMallAddress(address);

        String latitude = adminConfigMallPO.getMarket_mall_latitude();
        adminConfigMapper.updateMallLatitude(latitude);

        String longitude = adminConfigMallPO.getMarket_mall_longitude();
        adminConfigMapper.updateMallLongitude(longitude);

        String name = adminConfigMallPO.getMarket_mall_name();
        adminConfigMapper.updateMallName(name);

        String phone = adminConfigMallPO.getMarket_mall_phone();
        adminConfigMapper.updateMallPhone(phone);

        String qq = adminConfigMallPO.getMarket_mall_qq();
        adminConfigMapper.updateMallQQ(qq);
    }


    /**
     * 从market_system表中查询运费的配置信息，
     *
     * @return com.cskaoyan.bean.po.AdminConfigExpressPO
     * @author: Caspar CXC
     * @since 2022/06/26 20:13
     */
    @Override
    public AdminConfigExpressPO queryExpressConfig() {

        AdminConfigExpressPO adminConfigExpressPO = new AdminConfigExpressPO();

        String expressFreightMin = adminConfigMapper.queryMarketExpressFreightMin();
        adminConfigExpressPO.setMarket_express_freight_min(expressFreightMin);

        String expressFreightValue = adminConfigMapper.queryMarketExpressFreightValue();
        adminConfigExpressPO.setMarket_express_freight_value(expressFreightValue);
        return adminConfigExpressPO;
    }

    /**
     * 从market_system表中修改运费的配置信息，
     *
     * @param adminConfigExpressPO
     * @return void
     * @author: Caspar CXC
     * @since 2022/06/26 20:29
     */
    @Override
    public void updateMarketExpressConfig(AdminConfigExpressPO adminConfigExpressPO) {
        String min = adminConfigExpressPO.getMarket_express_freight_min();
        adminConfigMapper.updateExpressFreightMin(min);

        String value = adminConfigExpressPO.getMarket_express_freight_value();
        adminConfigMapper.updateExpressFreightValue(value);
    }

    /**
     * 从market_system表中查询订单的配置信息，
     *
     * @return com.cskaoyan.bean.po.AdminConfigOrderPO
     * @author: Caspar CXC
     * @since 2022/06/26 20:42
     */
    @Override
    public AdminConfigOrderPO queryOrderConfig() {
        AdminConfigOrderPO adminConfigOrderPO = new AdminConfigOrderPO();

        String unconfirm = adminConfigMapper.queryMarketOrderUnconfirm();
        adminConfigOrderPO.setMarket_order_unconfirm(unconfirm);

        String unpaid = adminConfigMapper.queryMarketOrderUnpaid();
        adminConfigOrderPO.setMarket_order_unpaid(unpaid);

        String comment = adminConfigMapper.queryMarketOrderComment();
        adminConfigOrderPO.setMarket_order_comment(comment);

        return adminConfigOrderPO;
    }

    /**
     * 修改market_system表中订单配置信息
     *
     * @param adminConfigOrderPO
     * @return void
     * @author: Caspar CXC
     * @since 2022/06/26 21:49
     */
    @Override
    public void updateMarketOrderConfig(AdminConfigOrderPO adminConfigOrderPO) {

        String unconfirm = adminConfigOrderPO.getMarket_order_unconfirm();
        adminConfigMapper.updateOrderUnconfirm(unconfirm);

        String unpaid = adminConfigOrderPO.getMarket_order_unpaid();
        adminConfigMapper.updateOrderUnpaid(unpaid);

        String comment = adminConfigOrderPO.getMarket_order_comment();
        adminConfigMapper.updateOrderComment(comment);
    }

    /**
     * 查询微信小程勋配置的信息并回显
     *
     * @return com.cskaoyan.bean.po.AdminConfigWxPO
     * @author: Caspar CXC
     * @since 2022/06/26 21:59
     */
    @Override
    public AdminConfigWxPO queryWxConfig() {

        AdminConfigWxPO adminConfigWxPO = new AdminConfigWxPO();

        String goods = adminConfigMapper.queryMarketWxGoods();
        String list = adminConfigMapper.queryMarketWxList();
        String brand = adminConfigMapper.queryMarketWxBrand();
        String hot = adminConfigMapper.queryMarketWxHot();
        String wxNew = adminConfigMapper.queryMarketWxNew();
        String topic = adminConfigMapper.queryMarketWxTopic();
        String share = adminConfigMapper.queryMarketWxShare();

        adminConfigWxPO.setMarket_wx_catlog_goods(goods);
        adminConfigWxPO.setMarket_wx_catlog_list(list);
        adminConfigWxPO.setMarket_wx_index_brand(brand);
        adminConfigWxPO.setMarket_wx_index_hot(hot);
        adminConfigWxPO.setMarket_wx_index_new(wxNew);
        adminConfigWxPO.setMarket_wx_index_topic(topic);
        adminConfigWxPO.setMarket_wx_share(share);

        return adminConfigWxPO;
    }

    /**
     * 修改微信小程勋配置的信息并回显
     *
     * @param adminConfigWxPO
     * @return void
     * @author: Caspar CXC
     * @since 2022/06/26 22:17
     */
    @Override
    public void updateMarketWxConfig(AdminConfigWxPO adminConfigWxPO) {
        String goods = adminConfigWxPO.getMarket_wx_catlog_goods();
        String list = adminConfigWxPO.getMarket_wx_catlog_list();
        String brand = adminConfigWxPO.getMarket_wx_index_brand();
        String hot = adminConfigWxPO.getMarket_wx_index_brand();
        String wxNew = adminConfigWxPO.getMarket_wx_index_brand();
        String topic = adminConfigWxPO.getMarket_wx_index_brand();
        String share = adminConfigWxPO.getMarket_wx_share();

        adminConfigMapper.updateMarketWxGoods(goods);
        adminConfigMapper.updateMarketWxList(list);
        adminConfigMapper.updateMarketWxBrand(brand);
        adminConfigMapper.updateMarketWxHot(hot);
        adminConfigMapper.updateMarketWxNew(wxNew);
        adminConfigMapper.updateMarketWxTopic(topic);
        adminConfigMapper.updateMarketWxShare(share);
    }
}
